<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" href="static/css/tcommon.css" />
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>技术论坛</title>
</head>

<body>
	<div class="content-container" data-options="region:'center'" title="技术论坛列表">
		<div class="panel-header">
			<div class="panel-title">帖子列表</div>
		</div>
		<table id="pro_table" class="easyui-datagrid" style="height: 100%">
		</table>
	</div>
</body>
<script th:inline="javascript">
	var currentPro;
	var currentChild;
	var userInfo =[[${userInfo}]];
	$(document).ready(function() {
		$('#pro_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#pro_tb',
			url : "forumPosts",
			method : 'get',
			queryParams : {
				status : 2,
				name : userInfo.name
			},
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'title',
				title : '帖子主题',
				width : '',
				formatter : function(value,row,index) {
					return '<a href="#" onclick="toreply(' + index + ')">'+value+'</a>'
				}
			},{
				field : 'name',
				title : '作者',
				width : '',
				formatter : function(value,row,index) {
					if (row.user != null){
						return row.user.name;
					}else{
						return "";
					}
				}
			},{
				field : 'replycount',
				title : '回复',
				width : ''
			},{
				field : 'updatetime',
				title : '最后发表',
				width : '',
				formatter : function(value,row,index) {
					if (row.updatetime == null){
						return formatDate(row.createdate);
					}else{
						return formatDate(row.updatetime);
					}
				}
			} ] ]
		});
	});
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear();
		var month = date.getMonth() + 1; //月份是从0开始的
		if (month < 10){
			month = "0" + month;
		}
		var day = date.getDate();
		if (day < 10){
			day = "0" + day;
		}
		var hour = date.getHours();
		if (hour < 10){
			hour = "0" + hour;
		}
		var min = date.getMinutes();
		if (min < 10){
			min = "0" + min;
		}
		var sec = date.getSeconds();
		if (sec < 10){
			sec = "0" + sec;
		}
		var newTime = year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec;
		return newTime;
	}

	function toreply(index) {
		var item = $("#pro_table").datagrid('getRows')[index];
		var title = '帖子详情';
		window.parent.window.addTab(title, "toreply.do?postid=" + item.id, item.id);
	}
</script>

</html>